//package com.booter.config;
//
//import com.fasterxml.jackson.annotation.JsonAutoDetect;
//import com.fasterxml.jackson.annotation.JsonTypeInfo;
//import com.fasterxml.jackson.annotation.PropertyAccessor;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
//import org.springframework.boot.context.properties.EnableConfigurationProperties;
//import org.springframework.cache.annotation.CachingConfigurer;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
//import org.springframework.data.redis.serializer.RedisSerializationContext;
//import org.springframework.data.redis.serializer.StringRedisSerializer;
////非starter方式集成redis
//@EnableConfigurationProperties(RedisProperties.class)
//@Configuration
//public class RedisConfig implements CachingConfigurer {
//
//    @Autowired
//    private RedisProperties properties;
//
//    @Bean
//    public LettuceConnectionFactory redisConnectionFactory() {
//        RedisConfiguration configuration = new RedisStandaloneConfiguration(this.properties.getHost(), this.properties.getPort());
//        ((RedisStandaloneConfiguration) configuration).setDatabase(this.properties.getDatabase());
//        ((RedisStandaloneConfiguration) configuration).setPassword(this.properties.getPassword());
//        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
//        poolConfig.setMaxIdle(this.properties.getLettuce().getPool().getMaxIdle());
//        poolConfig.setMinIdle(this.properties.getLettuce().getPool().getMinIdle());
//        poolConfig.setMaxTotal(this.properties.getLettuce().getPool().getMaxActive());
//        poolConfig.setMaxWaitMillis(this.properties.getLettuce().getPool().getMaxWait().toMillis());
//        LettucePoolingClientConfiguration.LettucePoolingClientConfigurationBuilder
//                builder = LettucePoolingClientConfiguration.builder().
//                commandTimeout(this.properties.getConnectTimeout());
//        builder.shutdownTimeout(this.properties.getLettuce().getShutdownTimeout());
//        builder.poolConfig(poolConfig);
//        LettuceClientConfiguration lettuceClientConfiguration = builder.build();
//        LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(configuration, lettuceClientConfiguration);
//        lettuceConnectionFactory.afterPropertiesSet();
//        return new LettuceConnectionFactory();
//    }
//
//    @Bean
//    public RedisSerializationContext<String, Object> redisSerializationContext() {
//        RedisSerializationContext.RedisSerializationContextBuilder<String, Object> builder = RedisSerializationContext.newSerializationContext();
//        ObjectMapper om = new ObjectMapper();
//        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
//        om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
//        Jackson2JsonRedisSerializer<Object> redisSerializer = new Jackson2JsonRedisSerializer<>(om, Object.class);
//        builder.key(new StringRedisSerializer());
//        builder.value(redisSerializer);
//        builder.hashKey(new StringRedisSerializer());
//        builder.hashValue(redisSerializer);
//        return builder.build();
//    }
//
//    @Bean
//    public RedisTemplate<String, Object> reactiveRedisTemplate(RedisConnectionFactory connectionFactory) {
//        RedisTemplate<String, Object> template = new RedisTemplate<>();
//        template.setConnectionFactory(connectionFactory);
//        template.setKeySerializer(new StringRedisSerializer());
//        template.setHashKeySerializer(new StringRedisSerializer());
//        return template;
//    }
//}
